package com.hbue.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbue.springboot.vo.WaterCountStatVo;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * 送水统计模块相关的映射器
 */
@Repository
public interface WaterCountStatMapper extends BaseMapper<WaterCountStatVo> {

    /**
     * 统计每个送水工为那些客户送水以及送水数量
     * @return 分页对象
     */
    @Select("SELECT w.worker_name , \n" +
            "GROUP_CONCAT(distinct c.cust_name) cust_details , \n" +
            "sum(h.send_water_count) send_water_count\n" +
            "from tb_worker w inner join tb_history h on w.id = h.worker_id \n" +
            "left join tb_customer c on c.id = h.cust_id\n" +
            "where w.deleted = 0 \n" +
            "group by w.worker_name\n" +
            "order by send_water_count desc")
    IPage<WaterCountStatVo> statWorkerSendWaterCount(IPage<WaterCountStatVo> page) ;
}
